﻿using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls.WebParts;

namespace BoldBrick.OneIntranet.HR.WebParts
{
	/// <summary>
	/// Base class for editor parts
	/// </summary>
	public abstract class BaseEditorPart : EditorPart
	{
	    #region ------ Internals: EditorPart overrides -----------------------------------------------

	    protected override void CreateChildControls()
	    {
	        base.CreateChildControls();

	        divError = new HtmlGenericControl("div")
	                       {
	                           ID = "divError",
	                           Visible = false,
	                       };
	        divError.Style[HtmlTextWriterStyle.Color] = "red";

	        this.Controls.Add(divError);
	    }

	    #endregion

	    #region ------ Interface for descendants -----------------------------------------------------

        private HtmlGenericControl divError;

        /// <summary>
	    /// Show error message
	    /// </summary>
	    /// <param name="message">Error message</param>
	    protected void ShowError(string message)
	    {
	        EnsureChildControls();

	        divError.InnerText = message;
	        divError.Visible = true;
	    }

	    /// <summary>
	    /// Hide error message
	    /// </summary>
	    protected void HideError()
	    {
	        divError.Visible = false;
	    }

	    #endregion
	}
}
